package cn.gjxblog.common.model;

import lombok.Data;

/**
 * @author gjx
 * @version v1.0
 * @Description  定义响应类
 * @date 2018/9/10 9:31
 */
@Data
public class HttpResult<T> {
    //成功
    private static  final Integer SUCCESS = 200;
    //失败
    private static  final Integer FAIL = 500;

    public int code;
    public String msg;
    private T result;

    public static HttpResult success(){
        return new HttpResult();
    }

    public static HttpResult success(Object data){
        return new HttpResult(ResponseCode.SUCCESS.code,ResponseCode.SUCCESS.msg,data);
    }


    public static HttpResult error(){
        return new HttpResult(ResponseCode.ERROR.code,ResponseCode.ERROR.msg);
    }


    public HttpResult(){
        this(ResponseCode.SUCCESS.code,ResponseCode.SUCCESS.msg);
    }

    public HttpResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public HttpResult(int code, String msg, T result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }




    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }
}

